package reflection.dproxy.misobject;

import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;
import java.lang.reflect.Proxy;

public class ViewProxy implements InvocationHandler {
	private Object obj;

	public ViewProxy(Object obj) {
		this.obj = obj; 
	}

	public static Object newInstance(Object obj, Class[] interfaces){
		return Proxy.newProxyInstance(obj.getClass().getClassLoader(), interfaces, new ViewProxy(obj));
	}
	
	@Override
	public Object invoke(Object proxy, Method method, Object[] args)
			throws Throwable {
		try {
			return method.invoke(obj, args);			
		} catch (Exception e) {
			System.out.println("Exception: " + e.getMessage());
		}
		
		Object result = null;
		return result;
	}

}
